package com.ruoyi.stock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockBanner;
import com.ruoyi.stock.service.IStockBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * banner图片Controller
 * 
 * @author xxb
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/stock/stockbanner")
@Api( tags = "banner图管理")
public class StockBannerController extends BaseController
{
    @Autowired
    private IStockBannerService stockBannerService;

    /**
     * 查询banner图片列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取banner图列表", response = List.class)
    public TableDataInfo list(StockBanner stockBanner)
    {
        startPage();
        List<StockBanner> list = stockBannerService.selectStockBannerList(stockBanner);
        return getDataTable(list);
    }

    /**
     * 导出banner图片列表
     */
    @Log(title = "banner图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockBanner stockBanner)
    {
        List<StockBanner> list = stockBannerService.selectStockBannerList(stockBanner);
        ExcelUtil<StockBanner> util = new ExcelUtil<StockBanner>(StockBanner.class);
        util.exportExcel(response, list, "banner图片数据");
    }

    /**
     * 获取banner图片详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stockBannerService.selectStockBannerById(id));
    }

    /**
     * 新增banner图片
     */
    @Log(title = "banner图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockBanner stockBanner)
    {
        return toAjax(stockBannerService.insertStockBanner(stockBanner));
    }

    /**
     * 修改banner图片
     */
    @Log(title = "banner图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockBanner stockBanner)
    {
        return toAjax(stockBannerService.updateStockBanner(stockBanner));
    }

    /**
     * 删除banner图片
     */
    @Log(title = "banner图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockBannerService.deleteStockBannerByIds(ids));
    }
}
